package com.cloudptt.api.product.func.voice;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.cloudptt.api.pjsip.api.SipManager;
import com.cloudptt.api.product.func.IBroadcast;
import com.cloudptt.api.product.log.Log;

public class VoiceReportBroadcast extends BroadcastReceiver implements IBroadcast
{
	private Context ctx = null;
	private VoiceReportListener listener = null;
	

	public VoiceReportBroadcast(Context ctx,VoiceReportListener listener)
	{
		this.ctx = ctx;
		this.listener = listener;
		this.ctx.registerReceiver(this, new IntentFilter(SipManager.ACTION_LBS_RECEIVE_ACK_MSG));
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		String action = intent.getAction();
		Log.e(VoiceReportFunc.Log_Key, "Action is " + action);
		if (action.equals(SipManager.ACTION_LBS_RECEIVE_ACK_MSG)) 
		{
			String voiceReportStr = intent.getStringExtra(SipManager.EXTRA_VOICE_REPORT);
			Log.e(VoiceReportFunc.Log_Key, "ACTION_LBS_RECEIVE_ACK_MSG voiceReportStr is " + voiceReportStr);

			if(voiceReportStr != null
					&& voiceReportStr.length() > 0)
			{
				if(this.listener != null)
				{
					this.listener.receiveVoiceReport(voiceReportStr);
				}
			}
		}
	}


	public void clearResource()
	{
		this.ctx.unregisterReceiver(this);
		this.ctx = null;
	}
}
